package com.itbaizhan.shopping_admin_service.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itbaizhan.shopping_admin_service.mapper.PermissionMapper;
import com.itbaizhan.shopping_common.pojo.Permission;
import com.itbaizhan.shopping_common.service.PermissionService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@DubboService
@Transactional
@Service
public class PermissionServiceImpl implements PermissionService {
	
	@Autowired
	private PermissionMapper permissionMapper;
	
	/**
	 * 添加权限
	 * @param permission
	 */
	public void add(Permission permission) {
		permissionMapper.insert(permission);
	}
	
	/**
	 * 修改权限
	 * @param permission
	 */
	public void update(Permission permission) {
		permissionMapper.updateById(permission);
	}
	
	/**
	 * 根据id查询权限
	 * @param id
	 * @return
	 */
	public Permission findById(Long id) {
		return permissionMapper.selectById(id);
	}
	
	/**
	 * 删除权限
	 * @param id
	 */
	public void delete(Long id) {
		permissionMapper.deleteById(id);
		permissionMapper.deletePermissionAllRole(id);
	}
	
	/**
	 * 分页查询权限
	 * @param page
	 * @param size
	 * @return
	 */
	public Page<Permission> search(int page, int size) {
		Page<Permission> permissionPage = permissionMapper.selectPage(new Page<>(page, size), null);
		return permissionPage;
	}
	
	/**
	 * 查询所有权限
	 * @return
	 */
	public List<Permission> findAll() {
		return permissionMapper.selectList(null);
	}
}
